# $Id: PKGBUILD 181880 2013-04-05 08:54:23Z svenstaro $
# Maintainer: Andrea Scarpino <andrea@archlinux.org>

pkgbase=kdebindings-python
pkgname=('kdebindings-python'
         'kdebindings-python2'
         'kdebindings-python-common')
pkgver=4.10.2
pkgrel=1
url='https://projects.kde.org/projects/kde/kdebindings/pykde4'
arch=('i686' 'x86_64')
license=('GPL' 'LGPL' 'FDL')
groups=('kdebindings')
makedepends=('cmake' 'automoc4' 'boost' 'kdepim-runtime' 'python2-pyqt'
             'pyqt' 'qscintilla' 'python2-sip' 'python-sip' 'mesa')
             source=("http://download.kde.org/stable/${pkgver}/src/pykde4-${pkgver}.tar.xz")
sha1sums=('a17d533fca8126970ec8886f55297f1005df3eb5')

build() {
  export PYTHONDONTWRITEBYTECODE="TRUE"

  mkdir build
  cd build
  cmake ../pykde4-${pkgver} \
    -DCMAKE_BUILD_TYPE=Release \
    -DKDE4_BUILD_TESTS=OFF \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DPYTHON_EXECUTABLE=/usr/bin/python3 \
    -DPYTHON_LIBRARY=/usr/lib/libpython3.3m.so.1.0 \
    -DPYKDEUIC4_ALTINSTALL=TRUE
  make
  cd ..

  mkdir build-python2
  cd build-python2
  cmake ../pykde4-${pkgver} \
    -DCMAKE_BUILD_TYPE=Release \
    -DKDE4_BUILD_TESTS=OFF \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DPYTHON_EXECUTABLE=/usr/bin/python2 \
    -DPYKDEUIC4_ALTINSTALL=TRUE
  make
}

package_kdebindings-python() {
  pkgdesc="A set of Python 3.x bindings for KDE"
  depends=('kdepim-runtime' 'pyqt' 'kdebindings-python-common')

  cd "${srcdir}"/build
  make DESTDIR="${pkgdir}" install
  
  # Provided by kdebindings-python-common
  rm -r "${pkgdir}"/usr/share/apps/pykde4/examples
  rm -r "${pkgdir}"/usr/share/sip/PyKDE4

  ln -s /usr/bin/pykdeuic4-3.3 "${pkgdir}"/usr/bin/pykdeuic4
}

package_kdebindings-python2() {
  pkgdesc="A set of Python 2.x bindings for KDE"
  depends=('kdepim-runtime' 'python2-pyqt' 'kdebindings-python-common')
  conflicts=('kdebindings-python<4.8.1-2')
 
  cd "${srcdir}"/build-python2
  make DESTDIR="${pkgdir}" install

  # Provided by kdebindings-python-common
  rm -r "${pkgdir}"/usr/share/apps/pykde4/examples
  rm -r "${pkgdir}"/usr/share/sip/PyKDE4

  # pykdeuic4 should point to the python3 version
  #rm "${pkgdir}"/usr/bin/pykdeuic4

  # Use the python2 executable
  find "${pkgdir}" -name '*.py' | xargs sed -i 's|#!/usr/bin/env python|#!/usr/bin/env python2|'
}

package_kdebindings-python-common() {
  pkgdesc="Common files shared between python2 and python3 kdebindings"
  depends=('qscintilla')
  conflicts=('kdebindings-python<4.8.1-2')

  cd build
  make DESTDIR="${pkgdir}" install

  rm -r "${pkgdir}"/usr/{bin,lib}
}
